import 'package:flutter/material.dart';
import 'package:flutter_massage/common_lib/extension/ex_widget.dart';
import 'package:flutter_massage/common_lib/index.dart';
import 'package:flutter_massage/common_lib/routers/route.dart';
import 'package:flutter_massage/common_lib/ui/common_component.dart';
import 'package:flutter_massage/generated/assets.dart';
import 'package:flutter_massage/pages/model/bean.dart';
import 'package:flutter_massage/pages/preject/detail/project_detail_page.dart';
import 'package:flutter_massage/pages/technician/technician_detail/technician_detail_page.dart';
import 'package:flutter_massage/values/colors.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class HomeRecommendTechnician extends StatelessWidget {
  const HomeRecommendTechnician(this.bean, {super.key});

  final TechnicianBean bean;

  @override
  Widget build(BuildContext context) {
    return ButtonWidget(
      onTap: () => CommonRoute.open(TechnicianDetailPage(bean)),
      hasInkWell: false,
      child: Column(
        children: [
          Stack(
            alignment: Alignment.bottomCenter,
            children: [
              AspectRatio(aspectRatio: 1, child: ImageWidget.url(bean.header ?? '', radius: 4.w)),
              Row(
                children: [
                  TextWidget.oneLine(
                    text: bean.distance ?? '',
                    fontSize: 10,
                    color: AppColors.white,
                    fontWeight: FontWeight.bold,
                  ),
                  const Spacer(),
                  Container(
                    padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 1.w),
                    decoration:
                        CommonDecoration.getShapeDecoration(gradient: CommonDecoration.xydGradient, radius: 2.w),
                    child: TextWidget.oneLine(text: bean.score ?? '', fontSize: 10, color: AppColors.white),
                  ),
                ],
              ).padding(left: 3.w, right: 3.w, bottom: 3.w),
            ],
          ),
          TextWidget.oneLine(
                  text: bean.name ?? '', fontSize: 12, color: AppColors.textLevelOne, fontWeight: FontWeight.bold)
              .paddingTop(3.w),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              const TextWidget.oneLine(text: '已服务人数', fontSize: 10, color: AppColors.textLevelOne),
              SizedBox(width: 4.w),
              TextWidget.oneLine(
                  text: (bean.servedNum ?? 0).toString(),
                  fontSize: 12,
                  color: AppColors.primaryGreen,
                  fontWeight: FontWeight.bold),
            ],
          ).paddingTop(3.w),
        ],
      ).card(radius: 5.w, padding: EdgeInsets.only(top: 5.w, left: 5.w, right: 5.w, bottom: 8.w)),
    );
  }
}

class HomeRecommendProject extends StatelessWidget {
  const HomeRecommendProject(this.bean, {super.key, this.rightWidget, this.bottomWidget, this.onTapOrder});

  final ProjectBean bean;

  final Widget? bottomWidget;
  final Widget? rightWidget;
  final VoidCallback? onTapOrder; //预约

  @override
  Widget build(BuildContext context) {
    return CommonListItemScaffold(
      contentPadding: EdgeInsets.fromLTRB(6.w, 6.w, 8.w, 6.w),
      left: ImageWidget.url(bean.itemImage ?? '', width: 88.w, height: 88.w, radius: 6.w),
      center: CommonMargin.width(12.w),
      right: rightWidget != null
          ? rightWidget!.height(88.w).expanded()
          : Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    TextWidget.oneLine(
                      text: bean.itemName ?? '',
                      fontSize: 15,
                      color: AppColors.textLevelOne,
                      fontWeight: FontWeight.bold,
                    ).expanded(),
                    TextWidget.oneLine(
                      text: '超${bean.chooseNum}选择',
                      fontSize: 10,
                      color: AppColors.textLevelTwo,
                      fontWeight: FontWeight.bold,
                    ),
                  ],
                ).paddingTop(6.w),
                TextWidget.moreLine(
                  text: bean.itemLabel ?? '',
                  fontSize: 12,
                  fontWeight: FontWeight.bold,
                  color: AppColors.textLevelTwo,
                ).paddingTop(4.w),
                const Spacer(),
                Row(
                  children: [
                    ButtonWidget.iconText(
                      Assets.svgIconDuration.toSvg(width: 12.w),
                      bean.itemTime ?? '',
                      textColor: AppColors.textLevelTwo,
                      fontSize: 12,
                    ).expanded(),
                    Align(
                      alignment: onTapOrder != null ? Alignment.centerLeft : Alignment.centerRight,
                      child: Text.rich(
                        TextSpan(
                          text: '¥',
                          children: [
                            TextSpan(
                              text: bean.itemPrice.removeYuan(),
                              style: const TextStyle(
                                fontSize: 17,
                                color: AppColors.primaryOrange,
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                          ],
                          style: const TextStyle(
                            fontSize: 12,
                            color: AppColors.primaryOrange,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                    ).expanded(),
                    if (onTapOrder != null)
                      ButtonWidget.text(
                        '预约',
                        width: 70.w,
                        height: 28.w,
                        borderRadius: 28.w,
                        gradient: CommonDecoration.xydGradient,
                        alignment: Alignment.center,
                        fontSize: 12,
                        fontWeight: FontWeight.bold,
                        textColor: AppColors.white,
                        onTap: onTapOrder,
                        hasInkWell: false,
                      ),
                  ],
                ).paddingBottom(2.w),
              ],
            ).height(88.w).expanded(),
      bottom: bottomWidget,
      onTap: () => CommonRoute.open(ProjectDetailPage(bean)),
    ).card(radius: 8.w);
  }
}

class CommonTitleComponent extends StatelessWidget {
  const CommonTitleComponent({super.key, required this.title, this.onTapAll});

  final String title;
  final VoidCallback? onTapAll;

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Assets.svgSectionTitleIcon.toSvg(width: 16.w),
        Row(
          children: [
            TextWidget.oneLine(
              text: title,
              fontSize: 14,
              color: AppColors.textLevelOne,
              fontWeight: FontWeight.bold,
            ).padding(left: 6.w, top: 2.w).expanded(),
            if (onTapAll != null)
              ButtonWidget.textIcon(
                '更多',
                Assets.svgArrowRightGray.toSvg(width: 8.w, color: AppColors.textLevelTwo),
                fontSize: 12,
                textColor: AppColors.textLevelTwo,
                fontWeight: FontWeight.bold,
                spacing: 4.w,
                hasInkWell: false,
                onTap: onTapAll,
              )
          ],
        ),
      ],
    );
  }
}
